unit spr_Suppliers;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, shbl_Directory, DB, FIBDataSet, FIBDatabase, pFIBDatabase,
  ExtCtrls, pFIBDataSet, ActnList, Buttons, GridsEh, DBGridEh,
  StdCtrls, ComCtrls, ToolWin, Mask, DBCtrlsEh, PropFilerEh, PropStorageEh,
  XLSExportComp, DBLookupEh, DBGridEhGrouping;

type
  TsprSuppliers = class(TshblDirectory)
    dsReferID: TFIBIntegerField;
    dsReferSHORTNAME: TFIBStringField;
    dsReferNAME: TFIBStringField;
    dsReferCODE: TFIBStringField;
    dsReferMETERPOLIT: TFIBSmallIntField;
    dsReferLCODE: TFIBStringField;
    dsReferRADDRESS: TFIBStringField;
    dsReferJADDRESS: TFIBStringField;
    dsReferPHONE: TFIBStringField;
    dsReferINN: TFIBStringField;
    dsReferOKONH: TFIBStringField;
    dsReferBIK: TFIBStringField;
    dsReferOKPO: TFIBStringField;
    dsReferRS: TFIBStringField;
    dsReferKRS: TFIBStringField;
    dsReferADMIN: TFIBStringField;
    dsReferGENBUHGALTER: TFIBStringField;
    dsReferMENABONENTS: TFIBStringField;
    dsReferADMINNAME: TFIBStringField;
    dsReferBANKORG: TFIBStringField;
    Label10: TLabel;
    eNameSearch: TDBEditEh;
    cbShowAllOrgs: TDBCheckBoxEh;
    dsReferIS_SUPPLIER: TFIBIntegerField;
    dsReferSUPPLIER: TFIBSmallIntField;
    Panel1: TPanel;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    Label14: TLabel;
    Label15: TLabel;
    Label16: TLabel;
    Label17: TLabel;
    Label18: TLabel;
    Label19: TLabel;
    Label20: TLabel;
    Label21: TLabel;
    DBEditEh1: TDBEditEh;
    DBEditEh5: TDBEditEh;
    DBEditEh6: TDBEditEh;
    DBEditEh2: TDBEditEh;
    DBEditEh3: TDBEditEh;
    DBEditEh7: TDBEditEh;
    DBEditEh4: TDBEditEh;
    DBEditEh8: TDBEditEh;
    DBEditEh9: TDBEditEh;
    DBEditEh10: TDBEditEh;
    DBEditEh11: TDBEditEh;
    DBEditEh12: TDBEditEh;
    DBEditEh13: TDBEditEh;
    DBEditEh14: TDBEditEh;
    DBEditEh15: TDBEditEh;
    DBEditEh16: TDBEditEh;
    DBEditEh17: TDBEditEh;
    DBEditEh18: TDBEditEh;
    DBEditEh19: TDBEditEh;
    dbcbSupplier: TDBCheckBoxEh;
    gbDeps: TGroupBox;
    Label4: TLabel;
    DBComboBoxEh1: TDBComboBoxEh;
    ToolBar2: TToolBar;
    ToolButton12: TToolButton;
    ToolButton13: TToolButton;
    ToolButton14: TToolButton;
    aNewDept: TAction;
    aEditDept: TAction;
    ADelDept: TAction;
    ToolButton15: TToolButton;
    dbgDeps: TDBGridEh;
    dsDepts: TpFIBDataSet;
    dsDeptsID: TFIBIntegerField;
    dscDepts: TDataSource;
    dsDeptsSUPPLIER_ID: TFIBIntegerField;
    dsReferIS_UK: TFIBIntegerField;
    DBCheckBoxEh1: TDBCheckBoxEh;
    dsDeptsNAME: TFIBStringField;
    Label22: TLabel;
    DBDateTimeEditEh1: TDBDateTimeEditEh;
    dsReferEDATE: TFIBDateField;
    dsReferCLOSED_RS: TFIBSmallIntField;
    DBCheckBoxEh2: TDBCheckBoxEh;
    dsReferPARENTID: TFIBIntegerField;
    Label23: TLabel;
    lcbParent: TDBLookupComboboxEh;
    dsParentList: TpFIBDataSet;
    dscParentList: TDataSource;
    dsParentListID: TFIBIntegerField;
    dsParentListSHORTNAME: TFIBStringField;
    procedure eNameSearchChange(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure aNewDeptExecute(Sender: TObject);
    procedure aEditDeptExecute(Sender: TObject);
    procedure ADelDeptExecute(Sender: TObject);
    procedure aPostExecute(Sender: TObject);
    procedure aInsertExecute(Sender: TObject);
    procedure aEditExecute(Sender: TObject);
    procedure dsReferAfterInsert(DataSet: TDataSet);
    procedure dsReferAfterEdit(DataSet: TDataSet);
    procedure dsDeptsBeforePost(DataSet: TDataSet);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  sprSuppliers: TsprSuppliers;

implementation

{$R *.dfm}

procedure TsprSuppliers.eNameSearchChange(Sender: TObject);
begin
  inherited;
  aAddSQLString.Clear;
  if eNameSearch.Text <> '' then
    aAddSQLString.Append(' and upper(u.NAME) like upper(''%' + eNameSearch.Text + '%'')');
  if cbShowAllOrgs.Checked then
    aAddSQLString.Append(' and getbit(u.supplier, 0) = 1');
  Timer1.Enabled := false;
  Timer1.Enabled := true;
end;

procedure TsprSuppliers.FormCreate(Sender: TObject);
begin
  inherited;
  aAddSQLString.Append(' and getbit(u.supplier, 0) = 1');
end;

procedure TsprSuppliers.aNewDeptExecute(Sender: TObject);
begin
  inherited;
  dsDepts.Insert;
  dsDeptsSUPPLIER_ID.Value := dsReferID.Value;
  dsDeptsNAME.AsString := ' ';
end;

procedure TsprSuppliers.aEditDeptExecute(Sender: TObject);
begin
  inherited;
  if dsDepts.RecordCount > 0 then
    dsDepts.Edit;
end;

procedure TsprSuppliers.ADelDeptExecute(Sender: TObject);
begin
  inherited;
  if dsDepts.RecordCount > 0 then
    dsDepts.Delete;
end;

procedure TsprSuppliers.aPostExecute(Sender: TObject);
begin
  if dsDepts.State in [dsEdit, dsInsert] then dsDepts.Post;
  inherited;
end;

procedure TsprSuppliers.aInsertExecute(Sender: TObject);
begin
  inherited;
  gbDeps.Enabled := false;
end;

procedure TsprSuppliers.aEditExecute(Sender: TObject);
begin
  inherited;
  gbDeps.Enabled := true;
  dsDepts.ParamByName('id').Value := dsReferID.Value;
  dsDepts.FullRefresh;
end;

procedure TsprSuppliers.dsReferAfterInsert(DataSet: TDataSet);
begin
  inherited;
  dsParentList.ParamByName('id').Value := dsReferPARENTID.Value;
  dsParentList.FullRefresh;
  if dsReferIS_SUPPLIER.IsNull then
    dsReferIS_SUPPLIER.AsInteger := 0;
  if dsReferIS_UK.IsNull then
    dsReferIS_UK.AsInteger := 0;
end;

procedure TsprSuppliers.dsReferAfterEdit(DataSet: TDataSet);
begin
  inherited;
  if dsReferIS_SUPPLIER.IsNull then
    dsReferIS_SUPPLIER.AsInteger := 0;
  if dsReferIS_UK.IsNull then
    dsReferIS_UK.AsInteger := 0;
end;

procedure TsprSuppliers.dsDeptsBeforePost(DataSet: TDataSet);
begin
  dsDeptsSUPPLIER_ID.Value := dsReferID.Value;

end;

end.
